<?php
/**
 * +----------------------------------------------------------------------
 * | summer framework
 * +----------------------------------------------------------------------
 * | Copyright (c) 2020 https://github.com/suframe/think-admin All rights reserved.
 * +----------------------------------------------------------------------
 * | Author: summer <806115620@qq.com>  2020/4/18 14:22
 * +----------------------------------------------------------------------
 */
declare (strict_types=1);

namespace app\mall\model\traits;

use app\mall\model\MallUserAddress;
use think\model\relation\HasOne;

/**
 * trait UserAddressTrait
 * @package app\mall\model\traits
 * @mixin \think\Model
 * @property integer address_id
 * @property MallUserAddress address
 */
trait UserAddressTrait
{

    /**
     * 获取会员
     * @return HasOne
     */
    public function address(): HasOne
    {
        return $this->hasOne(MallUserAddress::class, 'id',
            'address_id')->cache('modelHasOneUserAddress' . $this->address_id, 60);
    }

    /**
     * 获取会员名称
     * @return array
     */
    public function getAddressInfoAttr(): array
    {
        return $this->address->toArray();
    }

}